
from sqlalchemy import Column, Integer, String, Text, and_, exists, text
from app.entity.baseModal import BaseModal
from sqlalchemy.orm import Mapped,mapped_column,declarative_base, relationship,sessionmaker

from app.entity.projectUser import ProjectUser
from app.entity.user import User

class ProjectGroup(BaseModal):
    __tablename__="jz_project_group"
    _fieldIgnore = []
    projectId :Mapped[int]=mapped_column(Integer(),name="project_id")
    name :Mapped[str]=mapped_column(String(100))
    createdBy :Mapped[int]=mapped_column(Integer(),name="created_by")
    num :Mapped[int]=mapped_column(Integer())

    def getPeopleNumAttr(self):
        return ProjectUser().query().where(ProjectUser.defalutGroupId==self.id).count()

    def getPeopleListAttr(self):
        exis=exists(text('1')).where(and_(ProjectUser.defalutGroupId==self.id,ProjectUser.userId==User.id))
        return User().query().where(exis).with_entities(User.nickname,User.avatarUrl,User.id).all()
